#include<stdio.h>
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
bool hasCycle(struct ListNode* head) {
    struct ListNode* low = head;
    if (head == NULL)
        return false;
    struct ListNode* high = head->next;
    if (high == NULL)
        return false;

    while (high != low && high != NULL && high->next != NULL)
    {
        high = high->next->next;
        low = low->next;
    }

    if (high && high->next)
        return true;
    else
        return false;
}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {
    struct ListNode* cur = head;
    struct ListNode* newhead = NULL;
    while (cur)
    {
        struct ListNode* next = cur->next;
        cur->next = newhead;
        newhead = cur;
        cur = next;
    }
    return newhead;
}